<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
      xmlns:gqgy="http://www.thymeleaf.org/extras/gqgl">
<div th:replace="common/common::html"></div>
<head>
    <meta charset="UTF-8">
    <title th:text="#{user.manage}">Title</title>
    <script th:inline="javascript">
        var _gridWidth;
        var _gridHeight;
        //页面自适应
        function resizePageSize(){
            _gridWidth = $(document).width()-12;/*  -189 是去掉左侧 菜单的宽度，   -12 是防止浏览器缩小页面 出现滚动条 恢复页面时  折行的问题 */
            _gridHeight = $(document).height()-72-44;
        }
        function delConfig222(v) {
            $.ajax({
                type: 'post',
                async: false,
                dataType : 'json',
                url: /*[[@{deletelogInfoById}]]*/'',
                data: {id:v},
                success: function (data) {
                    alert("删除成功");
                },
                error: function(msg){
                    message(/*[[#{common.error}]]*/'');
                }

            });
            query();
        }
        $(function () {



            resizePageSize();
            var _columnWidth = _gridWidth/6;
            $("#flexigrid-id").flexigrid({
                width : _gridWidth,
                height : _gridHeight,
                url : /*[[@{querylogInfoListByPage}]]*/"",
                dataType : 'json',
                colModel : [
                    {display : 'logid',name : 'logid',width : 150,sortable : false,align : 'center',hide : 'true'},
                    {display : "系统",name : 'logsystem',width : _columnWidth, sortable : true,align : 'center'},
                    {display : "模块",name : 'logmodule',width : _columnWidth, sortable : true,align : 'center'},
                    {display : "动作",name : 'logaction',width : _columnWidth, sortable : true,align : 'center'},
                    {display : "内容",name : 'logcontents',width : _columnWidth, sortable : true,align : 'center'},
                    {display : "时间",name : 'createtime',width : _columnWidth, sortable : true,align : 'center'},
                    {display : "删除操作",name : 'logid',width : _columnWidth, sortable : true,align : 'center',process: function(v,_trid,_row) {
                            return  ' <a sec:authorize="hasRole(\'gqgy_data_log_delete\')" onclick="delConfig222(\''+ v +'\');"  >删除</a>';
                        }}
                ],
                resizable : false, //resizable table是否可伸缩
                useRp : true,
                usepager : true, //是否分页
                autoload : false, //自动加载，即第一次发起ajax请求
                hideOnSubmit : true, //是否在回调时显示遮盖
                showcheckbox : true, //是否显示多选框
                //rowhandler : rowDbclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                rowbinddata : true

            });
            query();
            function delConfig222(v) {

                $.ajax({
                    type: 'post',
                    async: false,
                    dataType : 'json',
                    url: /*[[@{deleteConfigInfoById}]]*/'',
                    data: [{id:v}],
                    success: function (data) {
                        alert("删除成功");
                    },
                    error: function(msg){
                        message(/*[[#{common.error}]]*/'');
                    }

                });
            }
            $("#query-btn-id").click(function (evnt) {
                evnt.stopPropagation();
                query();
            });

            $("#allocate-role-dialog-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{user.role.allocate}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {
                            var userUuid = $("#role-ztree-list-id").attr("userUuid");
                            var roleArray = [];
                            console.info(userUuid)

                            var ztreeObj = $.fn.zTree.getZTreeObj("role-ztree-list-id");
                            var checkNodes = ztreeObj.getCheckedNodes(true);
                            var menuArray = [];
                            $(checkNodes).each(function (index,item) {
                                roleArray.push(item.id);
                            });

                            $.ajax({
                                type: 'post',
                                async: false,
                                dataType : 'json',
                                url: /*[[@{saveUserIdAndRoleId}]]*/'',
                                data: [{name:"cfgid",value:cfgid}],
                                success: function (data) {
                                    $("#allocate-role-dialog-id").dialog('close');
                                    message(data.msg);
                                },
                                error: function(msg){
                                    message(/*[[#{common.error}]]*/'');
                                }

                            });
                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                ]
            });

            $("#allocate-btn-id").click(function (event) {
                event.stopPropagation()
                // $("#allocate-role-dialog-id").dialog('open');
                allocateRoleTree();

            })
        });//ready
        function query() {
            var userNameId = $("#logaction").val();
            var mobileId = $("#user-mobile-id").val();
            $("#flexigrid-id").flexOptions({
                extParam:[
                    {name:"logaction",value:userNameId}
                ]
            }).flexReload();

        }
        var allocateSetting = {
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
        function allocateRoleTree() {
            var ids =  $("#flexigrid-id").getFlexigridiAttrByIndex(0);
            if(ids.length != 1){
                message(/*[[#{common.select.one}]]*/)
                return
            }
            $("#role-ztree-list-id").attr("userUuid",ids);
            $.ajax({
                type: 'post',
                async: false,
                dataType : 'json',
                url: /*[[@{allocateRoleTree}]]*/'',
                data: [{name:"userUuid",value:ids}],
                success: function (data) {
                    // console.info(data)
                    $.fn.zTree.init($("#role-ztree-list-id"), allocateSetting, data);
                    $("#allocate-role-dialog-id").dialog('open');
                },
                error: function(msg){
                    message(/*[[#{common.error}]]*/'');
                }
            });
        }

        $("#modify-config-info-dialog-id").dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            resizable: false,
            title: /*[[#{user.modify.person.info}]]*/'',
            buttons: [
                {
                    text: /*[[#{common.confirm}]]*/'',
                    click: function () {
                        $("#modify-config-info-form-id").submit();
                    }

                },
                {
                    text: /*[[#{common.cancel}]]*/'',
                    click: function () {
                        $(this).dialog("close");
                    }

                }
            ]
        });


        //点击打开修改页面
        function  openmodify  (evnet) {
            evnet.stopPropagation()
            $("#modify-config-info-dialog-id").dialog('open');
        }

        $("#modify-config-info-form-id").ajaxForm({
            dataType: "json",
            success : function(data) {
                message(data.msg);
                $("#modify-config-info-dialog-id").dialog('close');
            },
            error : function() {
                message(/*[[#{common.error}]]*/'');
            }
        });


    </script>
    <style>
        body{
            background-color: #E6E6FA
        }
    </style>
</head>
<body>
<nav style="display: flex;flex-direction: row;margin-left: 10px;align-items: center">
    <div >
        <span th:text="操作动作"></span>
        <input  style="margin-left: 10px;" id="logaction">
        <a id="query-btn-id" class="navbar-btn" href="#" style="margin-left: 10px" >
            <i class="glyphicon glyphicon-zoom-in"></i>
            <span th:text="#{common.query}"></span>
        </a>
    </div>

</nav>
<table sec:authorize="hasRole('ROLE_gqgy_data_log_query')" id="flexigrid-id"></table>
<div id="allocate-role-dialog-id" style="display: none">
    <ul id="role-ztree-list-id" class="ztree">
    </ul>
</div>

</body>
</html>